package com.itheima.mapper;

import com.itheima.pojo.OrderPojo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;

@Mapper
public interface OrderMapper {
    /**
     * 根据预约日期和身份证号查询预约信息
     * @param orderDate
     * @param idCard
     * @return
     */
    @Select("select id, name, sex, telephone, id_card, validateCode, order_date, memberId, order_type, order_status, setmeal_id, marry, create_time  from `order` where order_date=#{orderDate} and id_card = #{idCard}")
    OrderPojo selectByIdCardAndOrderDate(String idCard, LocalDate orderDate);

    /**
     * 添加预约信息
     * @param selectOrderPojo
     */
    @Insert(" insert into `order`(name, sex, telephone, id_card, validateCode, order_date, memberId, order_type, order_status,\n" +
            "                            setmeal_id, marry, create_time)\n" +
            "        values (#{name}, #{sex}, #{telephone}, #{idCard}, #{validateCode}, #{orderDate}, #{memberId}, #{orderType},\n" +
            "                #{orderStatus}, #{setmealId}, #{marry}, #{createTime})")
    void add(OrderPojo selectOrderPojo);

    /**
     * 根据id查询预约信息
     * @param id
     * @return
     */
    @Select("select * from `order` where id = #{id}")
    OrderPojo getById(Integer id);
}
